// pages/vip/vip.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    money: '',
    un_click1: 'money_box',
    un_click2: 'money_box',
    un_click3: 'money_box',
    un_click4: 'money_box',
    un_click5: 'money_box',
    un_click6: 'money_box',
    context:''
  },
  lv1: function () {
    this.setData({
      money: '1',
      un_click2: 'money_box',
      un_click3: 'money_box',
      un_click4: 'money_box',
      un_click5: 'money_box',
      un_click6: 'money_box',
      un_click1: 'money_box1'
    })
  },
  lv2: function () {
    this.setData({
      money: '3',
      un_click2: 'money_box1',
      un_click3: 'money_box',
      un_click4: 'money_box',
      un_click5: 'money_box',
      un_click6: 'money_box',
      un_click1: 'money_box'
    })
  },
  lv3: function () {
    this.setData({
      money: '5',
      un_click2: 'money_box',
      un_click3: 'money_box1',
      un_click4: 'money_box',
      un_click5: 'money_box',
      un_click6: 'money_box',
      un_click1: 'money_box'
    })
  },
  lv4: function () {
    this.setData({
      money: '7',
      un_click2: 'money_box',
      un_click3: 'money_box',
      un_click4: 'money_box1',
      un_click5: 'money_box',
      un_click6: 'money_box',
      un_click1: 'money_box'
    })
  },
  lv5: function () {
    this.setData({
      money: '10',
      un_click2: 'money_box',
      un_click3: 'money_box',
      un_click4: 'money_box',
      un_click5: 'money_box1',
      un_click6: 'money_box',
      un_click1: 'money_box'
    })
  },
  lv6: function () {
    this.setData({
      money: '12',
      un_click2: 'money_box',
      un_click3: 'money_box',
      un_click4: 'money_box',
      un_click5: 'money_box',
      un_click6: 'money_box1',
      un_click1: 'money_box'
    })
  },
  onLoad:function(options){
   var that  = this;
   var bool = options.id;
    if(bool==1)
    {
      that.setData({
        context : '开通'
      })
    }
    else if(bool==2)
    {
      that.setData({
        context:'续费'
      })
    }
  },
  chongzhi: function () {
    var num = parseInt(this.data.money);
    var that  = this;
   if(that.data.context=='开通')
{
     wx.request({
       url: 'https://www.hkzhaoscut.top/newvip',
       data: {
         u_id: wx.getStorageSync("openid"),
         amount:num
       },
       success: function (res) {
         var code = res.statusCode;
         if (code == 200) {
           wx.showToast({
             title: '开通成功',
             icon: 'success',
             duration: 2000
           });
           wx.switchTab({
             url: '../wallet/wallet',
           })
         }
         else {
           wx.redirectTo({
             url: '../msg_fail/msg_fail',
           })
         }
       },
       fail: function () {
         wx.redirectTo({
           url: '../msg_fail/msg_fail',
         })
       }
     })
}
else
{
     wx.request({
       url: 'https://www.hkzhaoscut.top/plusvip',
       data: {
         u_id: wx.getStorageSync("openid"),
         amount:num
       },
       success: function (res) {
         var f = res.statusCode;
         if (f == 200) {
           wx.showToast({
             title: '续费成功',
             icon: 'success',
             duration: 2000
           });
           wx.switchTab({
             url: '../wallet/wallet',
           })
         }
         else {
           wx.redirectTo({
             url: '../msg_fail/msg_fail',
           })
         }
       },
       fail: function () {
         wx.redirectTo({
           url: '../msg_fail/msg_fail',
         })
       }
     })
}

  }
})